package com.settlement.system.model.entity.common;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.annotation.write.style.HeadStyle;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.settlement.system.common.enums.CostAllocationEnum;
import com.settlement.system.converter.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
 * 统一账单明细汇总
 * @author xiaochuan
 * @since 2021-01-20
 */
@Data
@ExcelIgnoreUnannotated
@HeadStyle(fillBackgroundColor = 9,fillForegroundColor = 9)
@HeadRowHeight(value = 20)
@HeadFontStyle(fontHeightInPoints = 14)
public class TblUnificationBillSummary extends BaseModel implements Serializable {


    /**
     * 统一账单汇总ID
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "统一账单汇总ID",converter = BigNumberFormatConvert.class)
    @ApiModelProperty(value = "统一账单汇总ID")
    private String summaryId;

    /**
     * 渠道编码
     */
    @ColumnWidth(13)
    @ExcelProperty(value = "渠道编码")
    @ApiModelProperty(value = "渠道编码")
    private String channelNo;

    /**
     * 渠道
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "渠道")
    @ApiModelProperty(value = "渠道")
    private String channelName;

    /**
     * 账单大类
     */
    @ColumnWidth(13)
    @ExcelProperty(value = "账单大类",converter = BillCategoryConvert.class)
    @ApiModelProperty(value = "账单大类（1、平台账单，2、营销工具，3、手工调账）")
    private String billCategory;

    /**
     * 账单类型
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "账单类型")
    @ApiModelProperty(value = "账单类型")
    private String billType;

    /**
     * 店铺编码
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "店铺编码")
    @ApiModelProperty(value = "店铺编码")
    private String shopNo;

    /**
     * 店铺名称
     */
    @ColumnWidth(30)
    @ExcelProperty(value = "店铺名称")
    @ApiModelProperty(value = "店铺名称")
    private String shopName;

    /**
     * 店铺账号
     */
    @ColumnWidth(30)
    @ExcelProperty(value = "店铺账号")
    private String shopAccount;

    /**
     * 日期
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "日期",converter = DateFormatConvert.class)
    @ApiModelProperty(value = "日期")
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    private Date outDate;

    /**
     * 记账项目
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "记账项目")
    @ApiModelProperty(value = "记账项目")
    private String recordAccountProject;

    /**
     * 账单金额
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "账单金额")
    @ApiModelProperty(value = "账单金额")
    private BigDecimal billAmount;

    /**
     * 不含税金额
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "不含税金额")
    private BigDecimal noTaxAmount;

    /**
     * 税额
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "税额")
    private BigDecimal taxAmount;

    /**
     * 会计期间
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "会计期间")
    @ApiModelProperty(value = "会计期间")
    private String accountingPeriod;

    /**
     * 入账主体
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "入账主体")
    @ApiModelProperty(value = "入账主体")
    private String companyNo;

    /**
     * 凭证类型
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "凭证类型")
    @ApiModelProperty(value = "凭证类型")
    private String voucherType;

    @ColumnWidth(13)
    @ExcelProperty(value = "是否分摊")
    private String shareOrNotStr;

    @ColumnWidth(13)
    @ExcelProperty(value = "票前票后")
    private String beforeOrAfterTicketStr;

    /**
     * NC_渠道
     */
    @ColumnWidth(16)
    @ApiModelProperty(value = "NC_渠道")
    private String ncChannelName;

    /**
     * NC_店铺编码
     */
    @ColumnWidth(16)
    @ApiModelProperty(value = "NC_店铺编码")
    private String ncShopNo;

    /**
     * NC_店铺名称
     */
    @ColumnWidth(20)
    @ApiModelProperty(value = "NC_店铺名称")
    private String ncShopName;

    /**
     * 供应商名称
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "供应商名称")
    @ApiModelProperty(value = "供应商名称")
    private String supplierName;

    /**
     * NC_供应商档案
     */
    @ColumnWidth(20)
    @ApiModelProperty(value = "NC_供应商档案")
    private String ncSupplierRecord;

    /**
     * NC_客户档案
     */
    @ColumnWidth(16)
    @ApiModelProperty(value = "NC_客户档案")
    private String ncCustomerRecord;

    /**
     * NC_虚拟账户
     */
    @ColumnWidth(16)
    @ApiModelProperty(value = "NC_虚拟账户")
    private String ncVirtualAccount;

    /**
     * NC_部门编码
     */
    @ColumnWidth(16)
    @ApiModelProperty(value = "NC_部门编码")
    private String ncDeptNo;

    /**
     * NC_收费项目
     */
    @ColumnWidth(16)
    @ApiModelProperty(value = "NC_收费项目")
    private String ncChargeProject;

    /**
     * 稽核标识
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "稽核标识")
    @ApiModelProperty(value = "稽核标识")
    private String auditMark;

    /**
     * 是否参与记账
     */
    @ColumnWidth(16)
    @ExcelProperty(value = "是否参与记账")
    @ApiModelProperty(value = "是否参与记账")
    private String isJoinRecordAccount;

    /**
     * 是否分摊
     */
    @ApiModelProperty(value = "是否分摊(1,是,  0否)")
    private String shareOrNot;

    /**
     * 票前票后
     */
    @ApiModelProperty(value = "票前票后(1,票前,  2票后,  3不涉及)")
    private String beforeOrAfterTicket;


    /**
     * 分摊状态
     */
    @ColumnWidth(13)
    @ExcelProperty(value = "分摊状态",converter = ShareStatusConvert.class)
    @ApiModelProperty(value = "分摊状态(0、无需分摊，1、未分摊，2、分摊中，3、已分摊，4、分摊失败)")
    private String shareStatus;

    @ApiModelProperty(value = "分摊状态(1、分摊权数不存在，2、查询不到该票后的供应商档案)")
    private String shareFailReason;

    public void setShareFailReason(String shareFailReason) {
        this.shareFailReason = shareFailReason;
        this.shareFailReasonStr = CostAllocationEnum.ShareFailReasonEnum.getNameByNo(shareFailReason);
    }

    @ColumnWidth(16)
    @ExcelProperty(value = "分摊失败原因")
    private String shareFailReasonStr;


    /**
     * 记账状态(0、未生成凭证，1、生成凭证中，8、生成凭证失败，2、已生成凭证，3、撤销生成中，4、推送NC中，5、已推送NC，6、推送NC失败，7、无需生成凭证)
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "记账状态",converter = AccountStatusConvert.class)
    @ApiModelProperty(value = "记账状态(0、未生成凭证，1、生成凭证中，8、生成凭证失败，2、已生成凭证，3、撤销生成中，4、推送NC中，5、已推送NC，6、推送NC失败，7、无需生成凭证)")
    private String accountStatus;

    /**
     * 记账失败原因
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "记账失败原因")
    @ApiModelProperty(value = "记账失败原因")
    private String accountFailDesc;

    public void setShareOrNot(String shareOrNot) {
        this.shareOrNot = shareOrNot;
        if(StringUtils.isNotEmpty(shareOrNot)){
            this.shareOrNotStr = shareOrNot.replace(CostAllocationEnum.ShareOrNotEnum.NO.getNo(), CostAllocationEnum.ShareOrNotEnum.NO.getName())
                    .replace(CostAllocationEnum.ShareOrNotEnum.YES.getNo(), CostAllocationEnum.ShareOrNotEnum.YES.getName());
        }
    }

    public void setBeforeOrAfterTicket(String beforeOrAfterTicket) {
        this.beforeOrAfterTicket = beforeOrAfterTicket;
        if(StringUtils.isNotEmpty(beforeOrAfterTicket)){
            this.beforeOrAfterTicketStr = beforeOrAfterTicket
                    .replace(CostAllocationEnum.BeforeOrAfterTicketEnum.AFTER.getNo(), CostAllocationEnum.BeforeOrAfterTicketEnum.AFTER.getName())
                    .replace(CostAllocationEnum.BeforeOrAfterTicketEnum.BEFORE.getNo(), CostAllocationEnum.BeforeOrAfterTicketEnum.BEFORE.getName())
                    .replace(CostAllocationEnum.BeforeOrAfterTicketEnum.NOT_INVOLVE.getNo(), CostAllocationEnum.BeforeOrAfterTicketEnum.NOT_INVOLVE.getName());
        }
    }
}
